package com.mulanweb.api.module.controller;

import com.jfinal.plugin.activerecord.Page;
import com.mulanweb.api.module.model.OperationHistory;
import com.mulanweb.api.module.model.Visa;
import com.mulanweb.api.module.model.VisaChild;
import com.mulanweb.db.common.SQLGenerateHelper;
import com.mulanweb.validator.annotation.ValidateFile;
import com.mulanweb.validator.annotation.ValidateForm;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/11/8 0008.
 */
@ValidateFile
public class VisaController extends BaseController {

    /**
     * 搜索签证信息
     */
    @ValidateForm
    public void search() {
        SQLGenerateHelper helper = new SQLGenerateHelper("visa", "create_time desc");
        helper.addIsNullCondition("delete_time");
        helper.addEqualsCondition("status_id","20");//过滤已下架商品
        Page<Visa> page = Visa.dao.paginate(getParaToInt("PageNumber"), getParaToInt("PageSize"), helper.getSqlSelect(), helper.getSqlExceptSelect(), helper.getQueryParas());
        returnPageModelJson(page);
    }

    @ValidateForm
    public void getVisaDetail() {
        int visaId = getParaToInt("visaId");
        Visa visa = Visa.dao.findById(visaId);
        returnSuccessJson(visa);
    }

    @ValidateForm
    public void getVisaChild() {
        Integer visaId = getParaToInt("visaId");
        List<VisaChild> visas = VisaChild.dao.find("SELECT * FROM visa_child WHERE parent_id = ? AND delete_time IS NULL", visaId);
        returnSuccessJson(visas);
    }
}
